package com.longge;

public class SumArray {

    // 升序数组，判断两数相加 =target 时间复杂度 O(n)

    public int[] sumArray(int[] arr, int target) {
        int left = 0, right = arr.length - 1;
        while (left <= right) {
            if (arr[left] + arr[right] > target) {
                right--;
            }
            if (arr[left] + arr[right] < target) {
                left++;
            }
            if (arr[left] + arr[right] == target) {
                return new int[]{left, right};
            }
        }
        return new int[]{};
    }

}
